<template>
	<view class="page">
		<TInput label="手机号码" :disabled="isChange" type="Number" :value="lostInfo.phone" v-model="lostInfo.phone" />
		<!-- <TInput label="密码" type="password" v-model="lostInfo.password" /> -->
		<TInput label="姓名" :disabled="isChange" type="text" v-model="lostInfo.name" />
		<TInput label="性别" :disabled="isChange" type="text" v-model="sex" />
		<TInput label="年龄" :disabled="isChange" type="text" v-model="lostInfo.age" />
		<TInput label="出生地" :disabled="isChange" type="text" v-model="lostInfo.birthplace" />
		<TInput label="家庭住址" :disabled="isChange" type="text" v-model="lostInfo.home_address" />
		<TInput label="工作地址" :disabled="isChange" type="text" v-model="lostInfo.work_address" />
		<!-- <TInput label="身份证号码" type="text" v-model="lostInfo.ID_number" /> -->
		<TInput label="职务" :disabled="isChange" type="text" v-model="lostInfo.position" />
		<TInput label="角色类型" :disabled="isChange" type="text" placeholder="家属、志愿者、救援者" v-model="role"/>
		<TInput label="教育水平" :disabled="isChange" type="text" v-model="lostInfo.edu_bg" />
		<view class="btn" @click="isChange ? (isChange = false) : send()">{{isChange ? '修改' : '确定修改'}}</view>
	</view>
</template>

<script>
	import TInput from '../../../components/inputItem/input.vue'
	import {
		getUserInfo,
		setUserInfo
	} from '../../../network/me.js'
	export default {
		components: {
			TInput
		},
		data() {
			return {
				isChange: true,
				lostInfo: {name: 'sd'},
				img_path: '',
				sex: '',
				role: '',
				roleList: ['家属', '志愿者', '救援队']
			};
		},
		created() {
			this.init()
		},
		methods: {
			async init() {
				const result = await getUserInfo()
				if (!result.flag) return 
				let info = result.data[0]
				this.lostInfo = {...info}
				this.sex = info.sex;
				this.role = info.role
				console.log(this.lostInfo)
			},
			async send() {
				this.isChange = true;
				this.lostInfo.sex = this.sex == "男" ? 1 : 0
				let role = this.roleList.indexOf(+this.role)
				this.lostInfo.role = role >= 0 ? role : 0
				console.log(this.lostInfo)
				const result = await setUserInfo({...this.lostInfo})
				console.log(result)
				if (!result.flag) result;
				uni.showToast({
					title: '修改成功',
					icon: 'none'
				})
				const res = await getUserInfo()
				console.log(res)
				if (!res.flag) return;
				this.$store.commit('setUserInfo', {
					...res.data[0],
					user_id: res.data[0].id,
					userName: res.data[0].name,
					url: res.data[0].url,
					phone: res.data[0].phone
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		background-color: #FFFFFF;

		.title {
			margin: 10px 10px 0;
			text-align: center;
			color: #999999;
		}

		.column {
			margin: 10px 10px;

			textarea {
				display: block;
				width: calc(100% - 10px);
				height: 70px;
				padding: 5px;
				margin-top: 10px;
				background: none;
				outline: none;
				border: 0.5px solid #dddddd;
				border-radius: 3px;
			}

			.choose {
				margin-top: 10px;
				display: flex;
				align-items: center;

				view {
					width: 80px;
					height: 80px;
					border: 1px solid #dddddd;
					border-radius: 3px;
					font-size: 50px;
					line-height: 80px;
					color: #999999;
					text-align: center;
				}

				image {
					margin-right: 20px;
					width: 80px;
					height: 80px;
				}
			}
		}

		.btn {
			width: 50%;
			margin: 30px auto;
			padding: 10px 0;
			background-color: #1CBAB6;
			color: white;
			text-align: center;
			border-radius: 30px;
			cursor: pointer;

			&:active {
				background-color: #999999;
				color: #333333;
			}
		}
	}
</style>
